/**
 * Created by CJB on 2017/11/6.
 */

(function(){
    var setting = {
        data: {
            key: {
                name:'label',
                title:'label'
            },
            simpleData: {
                enable: true,
                pIdKey:'parentId'
            }
        },
        callback: {
            onClick:menuClick
        }
    };
    $(function(){
        calcContent();
        getMenus();
        //修改用户信息
    	$("#updateUserInfo").click(function(){
    		$("#updateDialog").load(getPath() + "showUpdateUserView");
    	});
    	//更新用户密码
    	$("#updatePassword").click(function(){
    		$("#updatePasswordDialog").load(getPath() + "showUpdatePasswordView");
    	});

    });

    /**
     * 计算页面布局
     */
    function calcContent(){
        $("#content > div").height($("#content").height());
        $("#flashContent .user-info .fa-caret-down").mouseover(function(){
            $("#flashContent .user-info .user-menu").css('display','inline-block');
        });

        $("#flashContent .user-info").mouseleave(function(){
            $("#flashContent .user-info .user-menu").css("display","none");
        });
    }

    /**
     * 初始化菜单
     */
    function getMenus(){
        /*$.post(getPath()+"menu/treeMenuList",function(jsonStr){
            var menuList = eval("(" + jsonStr + ")");
            $.fn.zreeMenu.init($("#accordion"),setting,menuList);
        });*/
        post(getPath() + "base/menu/list/usermenus",{},function(menuList){
            $.fn.zreeMenu.init($("#accordion"),setting,menuList);
        })
    }

    function menuClick(data, event){
        event.preventDefault();
        if(data.url){
            var url = data.url;
            url = calMenuPageSize(url,data.controlHeight);
            $("#childrenFrame").attr("src",getPath() + url);
        }
    }

    function calMenuPageSize(url,controlHeight){
        if(url.indexOf("{pageSize}")!=-1){
            var pageSize = calPageSize(controlHeight);
            url = url.replace("{pageSize}",pageSize);
        }
        return url;
    }

//计算表格的宽度
    function calPageSize(controlHeight){
        var tableHeight = getWindowHeight() - 80 - 40 - 40 - 50 - controlHeight;//header:80,title:40,page:40,表格第一行：50
        var pageSize = parseInt(tableHeight/40);
        return pageSize;
    }

})();
